
var WaitQueueScn = cc.Scene.extend({
	onEnter:function(){
		this._super();
		var layer = new WaitQueueLayer();
		layer.init();
		this.addChild(layer);
	}
});

var WaitQueueLayer = cc.LayerColor.extend({
	init:function(){
		this._super();
		
		var size = cc.Director.getInstance().getWinSize();
		this.setColor(cc.c3b(0,0,0));
		
		var progress = cc.LabelTTF.create(S_TIP_LOADING + '0%', S_TIP_FONT);
		progress.setPosition(cc.p(size.width/2, size.height/2));
		this.addChild(progress);		
		
		var timeCount = cc.LabelTTF.create(S_TIP_WAITING+TW.queue_time+'s', S_TIP_FONT);
		timeCount.setPosition(cc.p(size.width/2, size.height/2+50));
		this.addChild(timeCount);
		
		var thiz = this;
		cc.Loader.getInstance().onloading = function(){
			progress.setString(S_TIP_LOADING+cc.Loader.getInstance().getProgressBar()+'%');
			thiz.draw();
		}
		cc.Loader.getInstance().onload = function(){			
			thiz.schedule(function(){
				timeCount.setString(S_TIP_WAITING+TW.queue_time+'s');
				TW.queue_time -= 1;
			}, 1);
			if(!TW.sock){
				return;
			}
			
			TW.sock.emit('sync');
			TW.sock.on('start', function(data){
				TW.room_w = data.w;
				TW.room_h = data.h;			
			});
			TW.sock.on('playerdata', function(pd){
				TW.players = TW.players || {};
				TW.players[pd.id] = pd;
				if(pd.self){
					TW.self = pd;
				}
			});
			TW.sock.on('startover', function(){
				initPlay();
				cc.Director.getInstance().replaceScene(new GameScn());
			});
		}
		cc.Loader.getInstance().preload(G_CORE_RES);
	}
});

var LoadResScn = cc.Scene.extend({
	onEnter:function(){
		this._super();
		cc.Loader.getInstance().onloading = function(){}
		cc.Loader.getInstance().onload = function(){}
		cc.Loader.getInstance().preload(G_CORE_RES);
	}
}); 